home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvi2xx / 2up.sty < prev    next >
Text File  |  1994-04-24  |  14KB  |  429 lines

  1. %Article: 10393 of comp.text.tex
  2. %From: tvz@zandtwerk.Princeton.EDU (Timothy Van Zandt)
  3. %Newsgroups: comp.text.tex
  4. %Subject: Here is a 2up.sty for LaTeX.
  5. %Message-ID: <14650@princeton.Princeton.EDU>
  6. %Date: 27 Sep 91 19:27:46 GMT
  7. %Organization: Princeton University, Princeton NJ
  8. %
  9. %I seem to remember recent inquiries here or in comp.lang.postscript about
  10. %printing TeX documents two-up. This can be achieved using a PostScript
  11. %filter and/or a dvidvi converter.
  12. %
  13. %Here is another solution. It is a document style option for LaTeX which
  14. %makes a few modifications to LaTeX's output routine. It does not require
  15. %a PostScript output device.
  16. %
  17. %
  18. %---------------------------BEGIN 2up.sty -----------------------------
  19. \def\fileversion{v0.9}
  20. \def\filedate{91/09/26}
  21. %%
  22. %% \CharacterTable
  23. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  24. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  25. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  26. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  27. %%   Dollar        \$     Percent       \%%     Ampersand     \&
  28. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  29. %%   Asterisk      \*     Plus          \+     Comma         \,
  30. %%   Minus         \-     Point         \.     Solidus       \/
  31. %%   Colon         \:     Semicolon     \;     Less than     \<
  32. %%   Equals        \=     Greater than  \>     Question mark \?
  33. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  34. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  35. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  36. %%   Right brace   \}     Tilde         \~}
  37. %%
  38. %% Document style option `2up', for use with LaTeX v2.09
  39. %% By Timothy Van Zandt, tvz@Princeton.EDU
  40. %%
  41. %% It is recommended that this documentation be kept with the style file.
  42. %%
  43. %% *******************************************************************
  44. %% **                         DESCRIPTION                           **
  45. %% *******************************************************************
  46. %%
  47. %% This is style prints a document two-up. It does this by making a few
  48. %% simple changes to LaTeX's output routine. It does not involve a dvidvi
  49. %% converter or PostScript code. It produces a standard dvi file.
  50. %%
  51. %% As long as you have or can generate the needed font bitmaps (e.g., pk
  52. %% files), fonts will not be scaled and output quality will be high.
  53. %% Non-standard font sizes are needed if the document is reduced.
  54. %% This is often necessary so that the two pages fit on the sheet of paper.
  55. %%
  56. %% If you have used `true' dimensions in your document, you cannot reduce
  57. %% it and you may find it impossible to fit the two pages on a single one.
  58. %% `true' dimensions are a no-no if you want to change the magnification
  59. %% of a document.
  60. %%
  61. %% Otherwise, this style option should be compatible with any LaTeX styles
  62. %% or options that do not change LaTeX's \@outputpage and \enddocument,
  63. %% macros and that do not modify the commands and parameters that these
  64. %% use in a non-standard way.
  65. %%
  66. %% In this documentation, the "source" layout is the layout of your document
  67. %% the way it is usually printed. The "target" layout is the layout when it
  68. %% is printed two-up.
  69. %%
  70. %% 
  71. %% *******************************************************************
  72. %% **                          PARAMETERS                           **
  73. %% *******************************************************************
  74. %%
  75. %% After inputing this file, you must set the following parameters
  76. %%    ***       ONCE AND ONLY ONCE, AND IN THIS ORDER.     ***
  77. %%
  78. %%
  79. %% 1. Target magnification. Use the command
  80. %%
  81. %%     \targetmag{<num>}
  82. %%
  83. %% where
  84. %%
  85. %%   a. <num> is integer nearest to 1000 times the magnification, or
  86. %%   b. <num> is \magstep<n> for a magnification of 1.2^n (n=0,...,5), or
  87. %%   c. <num> is \magstepminus<n> for a magnification of 1.2^{-n} (n=0,...,5).
  88. %%
  89. %% To minimize the number of non-standard font magnifications, use (b) or (c),
  90. %% and choose the magnification closest to 1 such that the source pages
  91. %% fit properly in the target output.
  92. %%
  93. %%
  94. %% 2. Source magnification. Use the command
  95. %%
  96. %%     \sourcemag{<num>}
  97. %%
  98. %% where <num> is as in (1), but for the source output.
  99. %%
  100. %%
  101. %% 3. Target paper width and height. Use:
  102. %%
  103. %%    \targetpaperwidth{<width>true<unit>}
  104. %%    \targetpaperheight{<height>true<unit>}
  105. %%
  106. %% where <unit> is cm, in, pt, etc., and <width> and <height> are the
  107. %% true width and height of the paper, when looking at the target output
  108. %% right side up.
  109. %%
  110. %%
  111. %% 4. Source paper width and height. Use:
  112. %%
  113. %%    \sourcepaperwidth{<width><unit>}
  114. %%    \sourcepaperheight{<height><unit>}
  115. %%
  116. %% where <unit>, <width> and <height> are as in (2), but for the source
  117. %% output.
  118. %%
  119. %%
  120. %% 5. Target layout. Use
  121. %%
  122. %%    \targetlayout{<layout>}
  123. %%
  124. %% where <layout> is "topbottom" if the two source pages are to be printed
  125. %% one on top of the other, or "sidebyside" if the two source pages are
  126. %% to be printed side by side. With the sidebyside layout and LaTeX's twoside
  127. %% option, odd pages always appear on the right and even pages appear on the
  128. %% left; blank pages are inserted if necessary.
  129. %%
  130. %%
  131. %%
  132. %% MAKE NO OTHER CHANGES TO YOUR DOCUMENT EXCEPT THE FOLLOWING:
  133. %%
  134. %% -- You have to see to it that the target output is printed with the
  135. %% correct orientation.
  136. %%
  137. %% -- You can use \emptytwouppage to insert a completely blank half page in
  138. %% the target, and \cleartwouppage to eject a complete target page. Ordinarily
  139. %% you do not need to use these commands.
  140. %%
  141. %%
  142. %% *******************************************************************
  143. %% **                          DEFAULTS                             **
  144. %% *******************************************************************
  145. %%
  146. %% The following commands set the parameters for some common sources and
  147. %% targets. The definitions of these commands are also useful examples.
  148. %%
  149. %%
  150. %% I. \twouparticle.
  151. %%
  152. %% Source: A portrait document on 8.5x11 inch paper with the standard margins
  153. %% used in the article document style and without marginal notes.
  154. %%
  155. %% Target: A landscape document on the same size paper, with the source
  156. %% pages printed side by side.
  157. %%
  158. %% Definition:
  159. %%
  160. %%    \targetmag{\magstepminus1}
  161. %%    \sourcemag{\magstep0}
  162. %%    \targetpaperwidth{11truein}
  163. %%    \targetpaperheight{8.5truein}
  164. %%    \sourcepaperwidth{8.5in}
  165. %%    \sourcepaperheight{11in}
  166. %%    \targetlayout{sidebyside}
  167. %%
  168. %% If you use narrower side margins than the default ones in the article
  169. %% document style, or if you use marginal notes, then you will need to
  170. %% to reduce the magnication to \magstepminus2 or lower or use
  171. %% \twouplegaltarget, defined below.
  172. %%
  173. %%
  174. %% II. \twouplegaltarget.
  175. %%
  176. %% Source: A portrait document on 8.5x11 inch paper with just about any
  177. %% margins and perhaps with marginal notes.
  178. %%
  179. %% Target: A landscape document on legal size paper (8.5x14 inches),
  180. %% with the source pages printed side by side.
  181. %%
  182. %% Definition: 
  183. %%
  184. %%    \targetmag{\magstepminus1}
  185. %%    \sourcemag{\magstep0}
  186. %%    \targetpaperwidth{14truein}
  187. %%    \targetpaperheight{8.5truein}
  188. %%    \sourcepaperwidth{8.5in}
  189. %%    \sourcepaperheight{11in}
  190. %%    \targetlayout{sidebyside}
  191. %%
  192. %%
  193. %% III. \twouplandscape.
  194. %%
  195. %% Source: A landscape document on 8.5x11 inch paper with just about any
  196. %% margins.
  197. %%
  198. %% Target: A portrait document on the same size paper, with the source pages
  199. %% stacked vertically.
  200. %%
  201. %% Definition:
  202. %%
  203. %%    \targetmag{\magstepminus2}
  204. %%    \sourcemag{\magstep0}
  205. %%    \targetpaperwidth{8.5truein}
  206. %%    \targetpaperheight{11truein}
  207. %%    \sourcepaperwidth{11in}
  208. %%    \sourcepaperheight{8.5in}
  209. %%    \targetlayout{topbottom}
  210. %%
  211. %%
  212. %% *******************************************************************
  213. %% **                      IMPLEMENTATION                           **
  214. %% *******************************************************************
  215. %%
  216. %%
  217. \typeout{Document style option: `2up' \fileversion \space\space <tvz>}
  218. %%
  219. %% Parameter registers:
  220. \newcount\@sourcemag
  221. \newdimen\@targetpaperwidth
  222. \newdimen\@targetpaperheight
  223. \newdimen\@sourcepagewidth
  224. \newdimen\@sourcepageheight
  225. \newif\if@sidebyside
  226. \@sidebysidetrue
  227. %%
  228. %% Registers used by output routing.
  229. \newif\if@firstpage
  230. \@firstpagetrue
  231. \newbox\@leftpage
  232. \newbox\@rightpage
  233. %%
  234. \def\targetmag#1{\mag #1}
  235. \def\sourcemag#1{\@sourcemag #1}
  236. \def\targetpaperwidth#1{\@targetpaperwidth #1}
  237. \def\targetpaperheight#1{\@targetpaperheight #1}
  238. %%
  239. %% \@sourcepagewidth and |\@sourcepageheight should be the unmagnified
  240. %% dimensions of the source page when measured without TeX's 1 inch margins.
  241. \def\sourcepaperwidth#1{%
  242.   \@sourcepagewidth #1
  243.   \advance\@sourcepagewidth by -2in
  244.   \divide\@sourcepagewidth by \@sourcemag
  245.   \multiply\@sourcepagewidth by 1000\relax}
  246. \def\sourcepaperheight#1{%
  247.   \@sourcepageheight #1
  248.   \advance\@sourcepageheight by -2in
  249.   \divide\@sourcepageheight by \@sourcemag
  250.   \multiply\@sourcepageheight by 1000\relax}
  251. \def\targetlayout#1{%
  252.   \def\@tempa{sidebyside}%
  253.   \def\@tempb{topbottom}%
  254.   \def\@tempc{#1}
  255.   \ifx\@tempa\@tempc
  256.     \@sidebysidetrue
  257.   \else
  258.     \ifx\@tempb\@tempc
  259.       \@sidebysidefalse
  260.     \else
  261.       \@latexerr{Valid target layouts are "sidebyside" and "topbottom"}\@eha
  262.     \fi
  263.   \fi}
  264. %%
  265. \def\magstepminus#1{%
  266.   \ifcase#1 \@m\or 833\or 694\or 579\or 482\or 401\fi\relax}
  267. \def\twouparticle{%
  268.   \targetmag{\magstepminus1}%
  269.   \sourcemag{\magstep0}%
  270.   \targetpaperwidth{11truein}%
  271.   \targetpaperheight{8.5truein}%
  272.   \sourcepaperwidth{8.5in}%
  273.   \sourcepaperheight{11in}%
  274.   \targetlayout{sidebyside}}
  275. \def\twouplegaltarget{%
  276.   \targetmag{\magstepminus1}%
  277.   \sourcemag{\magstep0}%
  278.   \targetpaperwidth{14truein}%
  279.   \targetpaperheight{8.5truein}%
  280.   \sourcepaperwidth{8.5in}%
  281.   \sourcepaperheight{11in}%
  282.   \targetlayout{sidebyside}}
  283. \def\twouplandscape{%
  284.   \targetmag{\magstepminus2}%
  285.   \sourcemag{\magstep0}%
  286.   \targetpaperwidth{8.5truein}%
  287.   \targetpaperheight{11truein}%
  288.   \sourcepaperwidth{11in}%
  289.   \sourcepaperheight{8.5in}%
  290.   \targetlayout{topbottom}}
  291. %%
  292. %% LaTeX's output page routine is modified so that it saves each page and
  293. %% prints out every two. Each page is centered in a half-page
  294. \def\@outputpage{%
  295.   \if@firstpage
  296.     \global\@firstpagefalse
  297.     \def\next{%
  298.       \@makepagebox\@leftpage
  299.       \stepcounter{page}}%
  300.     \if@sidebyside
  301.       \if@twoside
  302.         \ifodd\count\z@
  303.           \def\next{%
  304.             \@makeemptypage\@leftpage
  305.             \@outputpage}%
  306.         \fi
  307.       \fi
  308.     \fi
  309.   \else
  310.     \global\@firstpagetrue
  311.     \def\next{%
  312.       \@makepagebox\@rightpage
  313.       \@shiptwouppage
  314.       \stepcounter{page}}
  315.     \if@sidebyside
  316.       \if@twoside
  317.         \ifodd\count\z@
  318.         \else
  319.           \def\next{%
  320.             \@makeemptypage\@rightpage
  321.             \@shiptwouppage
  322.             \@outputpage}%
  323.         \fi
  324.       \fi
  325.     \fi
  326.   \fi
  327.   \next}
  328. %%
  329. %% This is the \shipout routine.
  330. \def\@shiptwouppage{
  331.   \if@sidebyside
  332.     \shipout\vbox{%
  333.       \vskip -1truein
  334.       \hbox{\hskip -1truein\box\@leftpage\box\@rightpage}}
  335.   \else
  336.     \shipout\hbox{%
  337.       \hskip -1truein
  338.       \vbox{\offinterlineskip\vskip -1truein \box\@leftpage\box\@rightpage}}
  339.   \fi}
  340. %%
  341. %% \@makepagebox is just like \@outputpage in \LaTeX's standard output
  342. %% routine, except that it saves the page in a box instead of shipping it out.
  343. \def\@makepagebox#1{%
  344.   \begingroup\catcode`\ =10 
  345.     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
  346.     \if@specialpage 
  347.       \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
  348.     \fi
  349.     \if@twoside 
  350.       \ifodd\count\z@
  351.         \let\@thehead\@oddhead \let\@thefoot\@oddfoot
  352.         \let\@themargin\evensidemargin
  353.       \else
  354.         \let\@thehead\@evenhead \let\@thefoot\@evenfoot
  355.         \let\@themargin\oddsidemargin
  356.       \fi
  357.     \else
  358.     \fi
  359.     \setbox#1=\vbox to \@sourcepageheight{%
  360.       \normalsize \baselineskip\z@ \lineskip\z@
  361.       \let\par\@@par
  362.       \vskip \topmargin
  363.       \hbox to \@sourcepagewidth{%
  364.         \hskip \@themargin
  365.         \vbox{%
  366.           \setbox\@tempboxa=\vbox to\headheight{%
  367.             \vfil
  368.             \hbox to\textwidth{%
  369.               \let\label\@gobble \let\index\@gobble \@thehead}}%
  370.           \dp\@tempboxa\z@
  371.           \box\@tempboxa
  372.           \vskip \headsep
  373.           \box\@outputbox
  374.           \baselineskip\footskip
  375.           \hbox to\textwidth{%
  376.             \let\label\@gobble \let\index\@gobble  \@thefoot}}
  377.         \hss}
  378.       \vss}%
  379.     \if@sidebyside
  380.       \global\setbox#1=\vbox to \@targetpaperheight{%
  381.         \vss
  382.         \hbox to .5\@targetpaperwidth{\hss\box#1\hss}
  383.         \vss}
  384.     \else
  385.       \global\setbox#1=\vbox to .5\@targetpaperheight{%
  386.         \vss
  387.         \hbox to \@targetpaperwidth{\hss\box#1\hss}
  388.         \vss}
  389.     \fi
  390.     \global\@colht\textheight
  391.   \endgroup
  392.   \let\firstmark\botmark}
  393. %%
  394. %% This is used to generate an empty page.
  395. \def\@makeemptypage#1{%
  396.   \if@sidebyside
  397.     \global\setbox#1=\vbox to \@targetpaperheight{\vss
  398.       \hbox to .5\@targetpaperwidth{\hss}}
  399.   \else
  400.      \global\setbox#1=\vbox to .5\@targetpaperheight{\vss
  401.        \hbox to .5\@targetpaperwidth{\hss\box#1\hss}}
  402.   \fi}
  403. %%
  404. %% Eject a page, even when there is only one source page on it.
  405. \def\cleartwouppage{%
  406.   \clearpage
  407.   \if@firstpage
  408.   \else
  409.     \twoupemptypage
  410.   \fi}
  411. %%
  412. \def\twoupemptypage{%
  413.   \clearpage
  414.   {\let\@makepagebox\@makeemptypage
  415.   \@outputpage}
  416.   \addtocounter{page}{-1}}
  417. %%
  418. %% This is LaTeX's standard \enddocument, except that we change \clearpage
  419. %% to \cleartwouppage.
  420. \def\enddocument{\@checkend{document}\cleartwouppage\begingroup  
  421.   \if@filesw \immediate\closeout\@mainaux 
  422.   \def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
  423.   \def\bibcite{\@testdef b}\@tempswafalse \makeatletter\input \jobname.aux
  424.   \if@tempswa \@warning{Label(s) may have changed.  Rerun to get
  425.   cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}
  426. %%
  427. \endinput
  428.  
  429.